package com.spice.service.entity.job;

import com.spice.common.util.ShellUtil;
import lombok.Getter;

import java.io.File;

/**
 * 回滚数据任务
 */
@Getter
public class RollbackJob extends Job {
    private static final String ROLLBACK_SHELL_PATH =
            new File("resources/shell/rollback.sh").getAbsolutePath();

    private static final String DATABASE_NAME = "spice_info_platform";

    private static final File backupFolder = new File("resources/backup/");

    private String rollbackFileName;

    public RollbackJob(String rollbackFileName) {
        this.rollbackFileName = rollbackFileName;
    }

    @Override
    protected Boolean runMethod() throws Exception {
        return ShellUtil.executeCommand(
                ROLLBACK_SHELL_PATH,
                DATABASE_NAME,
                new File(backupFolder,rollbackFileName).getAbsolutePath());
    }

}
